<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>区块链小游戏管理后台</title>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type"/>


    <style type="text/css">
        body {
            width: 100%;
            height: 100%;
            margin: 0;
            overflow: hidden;
        }
    </style>

    <meta charset="UTF-8">
    <script src="../scripts/jquery.min.js"></script>
    <script src="../scripts/miniui/miniui.js"></script>
    <link href="../scripts/miniui/themes/default/miniui.css" rel="stylesheet">
    <link href="../scripts/miniui/themes/icons.css" rel="stylesheet">
    <script src="../scripts/core.js"></script>
    <link href="../scripts/miniui/themes/pure/skin.css" rel="stylesheet">
</head>
<body>
<div class="mini-window" id="loginWindow" showCloseButton="false" showModal="true"
     style="width:350px;height:165px;" title="用户登录"
>

    <div id="loginForm" style="padding:15px;padding-top:10px;">
        <table>
            <tr>
                <td style="width:60px;"><label for="username$text">帐号：</label></td>
                <td>
                    <input class="mini-textbox" id="username" name="username"
                           required="true" style="width:150px;"/>
                </td>
            </tr>
            <tr>
                <td style="width:60px;"><label for="pwd$text">密码：</label></td>
                <td>
                    <input class="mini-password" id="pwd" name="pwd" onenter="onLoginClick"
                           required="true" requiredErrorText="密码不能为空"
                           style="width:150px;"/>
                </td>
            </tr>
            <tr>
                <td></td>
                <td style="padding-top:5px;">
                    <a class="mini-button" onclick="onLoginClick" style="width:60px;">登录</a>
                    <a class="mini-button" onclick="onResetClick" style="width:60px;">重置</a>
                </td>
            </tr>
        </table>
    </div>

</div>


<script type="text/javascript">
    var userId, token;
    mini.parse();

    var loginWindow = mini.get("loginWindow");
    loginWindow.show();

    function onLoginClick(e) {
        var form = new mini.Form("#loginWindow");
        var data = form.getData();
        var json = mini.encode(data);

        $.ajax({
            url: "/auth/cmsLogin",
            data: json,
            type: "post",
            contentType: 'application/json',
            success: function (text) {
                var resp = mini.decode(text)
                if (resp.code == 200) {
                    userId = resp.data.userId;
                    token = resp.data.token;
                    var ss = "main.html?userId=" + userId + "&token=" + token;
                    window.location = ss;
                } else {
                    mini.alert("登录错误码:" + resp.code);
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });
    }

    function onResetClick(e) {
        var form = new mini.Form("#loginWindow");
        form.clear();
    }

    /////////////////////////////////////
    function isEmail(s) {
        if (s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
            return true;
        else
            return false;
    }

    function onUserNameValidation(e) {
        if (e.isValid) {
            if (isEmail(e.value) == false) {
                e.errorText = "必须输入邮件地址";
                e.isValid = false;
            }
        }
    }

    function onPwdValidation(e) {
        if (e.isValid) {
            if (e.value.length < 5) {
                e.errorText = "密码不能少于5个字符";
                e.isValid = false;
            }
        }
    }
</script>

</body>
</html>